package top.fzqblog.firstapp;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import top.fzqblog.adapter.MyFragmentPagerAdapter;
import top.fzqblog.adapter.ViewPageAdapter;
import top.fzqblog.fragment.fragment1;
import top.fzqblog.fragment.fragment2;
import top.fzqblog.fragment.fragment3;
import top.fzqblog.fragment.fragment4;

/**
 * Created by 抽离 on 2017/8/18 0018.
 */

public class ViewPageTest extends FragmentActivity implements ViewPager.OnPageChangeListener{

    private List<View> viewList = new ArrayList<>();

    private List<Fragment> fragmentList = new ArrayList<>();

    private  List<String> titleList = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainviewpage);

        /**
         * 提前把要呈现滑动的是图准备好
         */
        View view1 = View.inflate(this, R.layout.viewpage1, null);
        View view2 = View.inflate(this, R.layout.viewpage2, null);
        View view3 = View.inflate(this, R.layout.viewpage3, null);
        View view4 = View.inflate(this, R.layout.viewpage4, null);

        viewList.add(view1);
        viewList.add(view2);
        viewList.add(view3);
        viewList.add(view4);

        fragmentList.add(new fragment1());
        fragmentList.add(new fragment2());
        fragmentList.add(new fragment3());
        fragmentList.add(new fragment4());

        titleList.add("标题1");
        titleList.add("标题2");
        titleList.add("标题3");
        titleList.add("标题4");

        ViewPageAdapter viewPageAdapter = new ViewPageAdapter(viewList, titleList);

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);//静态方式使用ViewPager

        MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList, titleList);

//        PagerTabStrip pagerTabStrip = (PagerTabStrip) findViewById(R.id.tabstrip);
//        pagerTabStrip.setBackgroundColor(Color.YELLOW);
//        pagerTabStrip.setDrawFullUnderline(false);
//        pagerTabStrip.setTextColor(Color.BLUE);
//        pagerTabStrip.setTabIndicatorColor(Color.GREEN  );


        viewPager.setOnPageChangeListener(this);


//        viewPager.setAdapter(viewPageAdapter);
        viewPager.setAdapter(viewPageAdapter);
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//        Toast.makeText(this, "在第" + (position+1) + "个页面", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPageSelected(int position) {
        Toast.makeText(this, "在第" + (position+1) + "个页面", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
